/* eslint-disable @typescript-eslint/camelcase */
// import { login, getUserInfo } from '../services/home';
import { 
  getHome, login, getUserInfo,
  basicFormOperation, getStreet,
  getBasicForm, postBasicForm, putBasicForm,
  getBusinessForm, postBusinessForm, putBusinessForm,
  getRewardsForm, postRewardsForm, putRewardsForm,
  getHonorForm, postHonorForm, putHonorForm,
  getTecForm, postTecForm, putTecForm, 
  getProductForm, postProductForm, putProductForm,
} from '../services/home'


const Model = {
  namespace: 'home',

  state: {
    userinfo: {
      name: '超级管理员',
      avatar: "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
    },
    // 是否拿全局数据
    status: true,
    // 主页
    homePage: {
      totalCard: [[],[],[],[],[]],
      salesData: [],
      rankingListData: []
    },
    // 企业基本信息
    companyInformation: {
      // 企业信息表
      tableBasicList: [],
    },
    // 走访记录
    recordInformation: {
      // 走访记录表
      recordList: []
    },
    // 管理员信息
    users_system: []
  },

  effects: {
    // 登陆
    *login({ payload }, { call, put }) {
      const response = yield call(login, payload);
      console.log(response)
      // return
      if (response.Status === 1) {
        localStorage.setItem('tk',response.tk)
        const userInfo = yield call(getUserInfo, response.UserId);
        console.log(userInfo)
        // const response2 = yield call(getHome, payload)
        // yield put({
        //   type: 'update',
        //   payload: { response2 },
        // })
        // console.log(response2)
      }
      return response
    },

    // eslint-disable-next-line require-yield
    *getHome({ payload }, { call, put }) {
        // 请求
        const response = yield call(getHome, payload)
        yield put({
            type: 'save',
            payload: { response },
        })
        return 200
    },
    
    
    // 获取企业信息表
    *getBasicForm({ payload }, { call, put }) {
      // 请求
      const response = yield call(getBasicForm, payload)
      const CompanyList = []
      if (response) {
        response.forEach(val => {
          CompanyList.push({
            key: val.Id,
            // 企业名称
            name: val.Name,
            // 所在街道
            street: '街道',
            // 行业类型
            industry: val.Industry,
            // 产品数量
            numble: 1,
            // 法人代表
            owner: val.Man,
            // 联系电话
            phone: val.RelTel,
            // 信息完善率
            status: Math.floor(Math.random() * 10),
            // 联系人
            contact: val.RelMan,
            // 职务
            job: val.RelDuty
          })
        })
      }

      const HomePage = {
        companyInformation: {
          tableBasicList: CompanyList
        }
      }

      yield put({
          type: 'save',
          payload: { HomePage },
      })
      return CompanyList
    },

    // 获取街道信息
    *getStreet({ payload }, { call, put }) {
      const response = yield call(getStreet, payload)
      console.log(response)
      return response
    },


    // 企业信息表操作
    *basicFormOperation({ payload }, { call, put }) {
      const { text } = payload
      const response = yield call(basicFormOperation, text)
      const CompanyList = []
      if (response) {
        response.forEach(val => {
          CompanyList.push({
            key: val.Id,
            // 企业名称
            name: val.Name,
            // 所在街道
            street: '街道',
            // 行业类型
            industry: val.Industry,
            // 产品数量
            numble: 1,
            // 法人代表
            owner: val.Man,
            // 联系电话
            phone: val.RelTel,
            // 信息完善率
            status: Math.floor(Math.random() * 10),
            // 联系人
            contact: val.RelMan,
            // 职务
            job: val.RelDuty
          })
        })
      }
      return CompanyList

    },
    




    // 企业信息
    // 删除行
    *delColBasicList( { payload }, { call, put } ) {
      const { keys, home } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        if (keys === val.key) {
          home.companyInformation.tableBasicList.splice(index, 1)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    
    *delColRecordList( { payload }, { call, put } ) {
      const { keys, home } = payload
      home.recordInformation.recordList.forEach((val, index) => {
        if (keys === val.key) {
          home.recordInformation.recordList.splice(index, 1)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200

    },
    *addColRecordList( { payload }, { call, put } ) {
      const { newList, home } = payload
      home.recordInformation.recordList.unshift(newList)
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },





    // 新增企业信息
    *postBasicForm( { payload }, { call, put } ) {
      const { newList, home } = payload
      const param = {
        Name: newList.name,
        Industry: newList.industry,
        Man: newList.owner,
        StreetId: 1,
        RelMan: newList.contact,
        RelTel: newList.phone,
        RelDuty: newList.job,
      }
      console.log(newList)
      
      const res = yield call(postBasicForm, param)
      const new_company = {
        key: res.Id,
        // 企业名称
        name: res.Name,
        // 所在街道
        street: res.StreetId,
        // 行业类型
        industry: res.StreetId,
        // 产品数量
        numble: '0',
        // 法人代表
        owner: res.Man,
        // 联系电话
        phone: res.RelTel,
        // 信息完善率
        status: Math.floor(Math.random() * 10),
        // 联系人
        contact: res.RelMan,
        // 职务
        job: res.RelDuty
      }

      // home.companyInformation.tableBasicList.unshift(new_company)
      console.log(new_company)
      
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return new_company
    },
    
    // 编辑企业概况
    *edit_basicInform( { payload }, { call, put } ) {
      const { params, home, key } = payload
      const oldData = yield call(getBasicForm, {id: Number(key)})
      const data = {
        Man: params.man,
        RelMan: params.contact_people,
        RelDuty: params.contact_job,
        RelTel: params.contact_phone,
        Id: Number(key),
        Name: params.name,            // 企业名称
        Industry: params.industry,    // 行业类别
        Code: params.code,            // 机构代码
        RelAddress:params.address,    // 联系地址
        HourseType: 1,   // 用地类型
        HourseArea: params.landuse_area,   // 用地面积
        HourseIsEx: params.isAddAssetsRate, // 是否有增资需求率
        HourseTime: params.landuse_date.toString(),   // 用地／租赁到期时间
        IsCatalog: 0,
        Time: params.create_time.toString(),  // 成立时间
        Money: parseFloat(params.register_money),       // 注册资金
        IsList: params.islisted,                        // 是否上市
        Address: params.details_address,     // 注册地址
        Scope: params.range,           // 经营范围
        PeopleNum: Number(params.staff_total),    // 在岗总职工
        People: "",
        // 
        // staff_manage: '123',       // 管理人员
        // staff_technology: '144',   // 专业技术人员
        // staff_else: '182',         // 其他人员
      }
      const res = yield call(putBasicForm, {data, id: Number(key)})

      yield put({
        type: 'update',
        payload: { ...home },
      })
      return res
    },

    // 企业基本信息详情详情页
    *getCompanyDetials( { payload }, { call, put } ) {
      const { id, home } = payload

      // 基本数据
      const basicData = yield call(getBasicForm, { id })
      console.log('基本数据----->>>>>', basicData)
      // 经营数据
      const businesData = yield call(getBusinessForm, id)
      console.log('经营数据----->>>>>', businesData)
      // 奖励表
      const rewardsData = yield call(getRewardsForm, id)
      const newRewards = []
      if (rewardsData) {
        // eslint-disable-next-line array-callback-return
        rewardsData.map( item => {
          newRewards.push({
            EntId: item.EntId,
            key: item.Id,
            reward_department: item.Department,
            reward_project: item.ProjectName,
            reward_money: item.Num,
            reward_date: Number(item.Time),
          })
        })
      }
      console.log('奖励数据----->>>>>', newRewards)

      // 主要荣誉
      const honorData = yield call(getHonorForm, id)
      console.log('主要荣誉----->>>>>', honorData)
      const newHonor = []
      if (honorData) {
        // eslint-disable-next-line array-callback-return
        honorData.map( item => {
          newHonor.push({
            EntId: item.EntId,
            key: item.Id,
            honor_name: item.Name,
            honor_date: Number(item.Time),
            honor_introduce: item.Mask,
            honor_unit: item.Department,
          })
        })
      }
      // 创新技术
      const tecData = yield call(getTecForm, id)
      console.log('创新技术----->>>>>', tecData)
      const newTec = []
      if (tecData) {
        // eslint-disable-next-line array-callback-return
        tecData.map( item => {
          newTec.push({
            EntId: item.EntId,
            key: item.Id,
            core: item.Name,
            field: item.Advantage,
            introduce: item.Mask,
          })
        })
      }
      // 产品表
      const proData = yield call(getProductForm, id)
      console.log('创新技术----->>>>>', proData)
      const newPro = []
      if (proData) {
        // eslint-disable-next-line array-callback-return
        proData.map( item => {
          newPro.push({
            EntId: item.EntId,
            key: item.Id,
            // introduce: item.EntId,
            isshouantai: Number(item.IsFirst),
            iszhuanli: Number(item.IsHasRight),
            market: item.Market,
            product: item.Name,
            product_type: item.Mask,
            proportion: item.Percent,
            sales: item.Sale,
          })
        })
      }



      


      const newCompanyDetials = {
        // 企业信息（录入）
        infoData: {
            // 企业概况
            profile: basicData ? {
              id: basicData[0].Id,
              name: basicData[0].Name,               // 企业名称
              create_time: Number(basicData[0].Time),        // 成立时间
              code: basicData[0].Code,               // 机构代码
              industry: basicData[0].Industry,             // 行业类别
              register_money: basicData[0].Money ? basicData[0].Money : '',     // 注册资金
              register_address: basicData[0].Address ? basicData[0].Address : '',   // 注册地址
              islisted: basicData[0].IsList ? basicData[0].IsList : 0,      // 是否上市 1 上市 0 没上市
              manage_range: basicData[0].Scope ? basicData[0].Scope : '',       // 经营范围
              owner: basicData[0].Man,              // 法定代表人
              contact_people: basicData[0].RelMan,     // 联系人
              contact_job: basicData[0].RelDuty,        // 联系人职务
              contact_phone: basicData[0].RelTel,     // 联系人电话
              address: basicData[0].RelAddress ? basicData[0].RelAddress : '',            // 地址
              landuse_type: basicData[0].HourseType,       // 用地类型
              landuse_area: basicData[0].HourseArea,       // 用地面积
              landuse_date: Number(basicData[0].HourseTime),       // 用地／租赁到期时间
              isAddAssetsRate: basicData[0].HourseIsEx ? basicData[0].HourseIsEx : 0,    // 是否增资产需求率 1 是 0 不是
              staff_total: basicData[0].PeopleNum ? basicData[0].PeopleNum : '',        // 在岗总职工
              // staff_manage: '123',       // 管理人员
              // staff_technology: '144',   // 专业技术人员
              // staff_else: '182',         // 其他人员
            } : {},
            // 企业经营数据
            business: businesData ? {
              Id: businesData[0].Id,
              total_property: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',     // 总资产（万元）
              fixed_property: businesData[0].Fixdmeans ? businesData[0].Fixdmeans : '',    // 固定资产（万元）
              owe_rate: businesData[0].Debtratio ? businesData[0].Debtratio : '',     // 资产负债率（%）
              // 近二年经营情况
              pastyear_business: {
                  ll_year: businesData[0].Income1 ? businesData[0].Income1 : '',       // 2017年总产值（或销售收入）万元
                  l_year: businesData[0].Income2 ? businesData[0].Income2 : '',        // 2018年总产值（或销售收入）万元
                  // rate: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',           // 同比增减率
              },
              // 近二年研发投入情况
              pastyear_research: {
                  // 2017年
                  ll_year: businesData[0].Outcome1 ? businesData[0].Outcome1 : '',
                  // 2018年
                  l_year: businesData[0].Outcome2 ? businesData[0].Outcome2 : '',
              },
              // 纳税总值
              tax_total: {
                  total: businesData[0].Taxtotal ? businesData[0].Taxtotal : '',         // 净纳税总税（万元）
                  ll_year: businesData[0].Tax1 ? businesData[0].Tax1 : '',       // 2017年纳税总税（万元）
                  l_year: businesData[0].Tax2 ? businesData[0].Tax2 : '',         // 2018年纳税总税（万元）
                  // rate: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',           // 同比增减率
              },
              // situation: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',  // 经营情况说明
              // isunicorn: 1, // 是否独角兽企业
              // islisted: 1,  // 是否专精特新
              // isfivetop: 1, // 是否类五百强
              // options: ['创新百强','增值百强','产值百强','纳税百强','出口百强'],
              // 企业资质（2018年）
              // record_details: {
              //     // 2016
              //     llyear: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',
              //     // 2017
              //     lyear: businesData[0].Totalmeans ? businesData[0].Totalmeans : '',
              // } 
            } : {},
            // 主营产品
            product: proData ? newPro : [],
            // 科技创新
            innovation: tecData ? newTec :[],
            // 奖励
            reward: rewardsData ? newRewards : [],
            // 主要荣誉
            honor: honorData ? newHonor : [],
            // 企业诉求
            appeal: "",
            // 自荐入库理由
            reason: "",
        },
        // 变更记录
        change_record: [],
        // 制表记录
        tabulating_record: [],
      }
      console.log(newCompanyDetials)

      yield put({
        type: 'update',
        payload: { ...home },
      })
      return newCompanyDetials
    },

    // 新增企业经营数据
    *add_businessForm( { payload }, { call, put } ) {
      const { params, home, key } = payload
      const data = {
        EntId: parseFloat(key),
        Totalmeans: parseFloat(params.total_property),  // 总资产（万元）
        Fixdmeans: parseFloat(params.fixed_property),   // 固定资产（万元）
        Aptitude: 1,  // 资质
        Debtratio: parseFloat(params.owe_rate),   // 负债比率
        Income1: parseFloat(params.pastyear_business.ll_year), // 近两年经营情况
        Income2: parseFloat(params.pastyear_business.l_year),
        Outcome1: parseFloat(params.pastyear_research.ll_year),  // 近两年研发情况
        Outcome2: parseFloat(params.pastyear_research.l_year),
        Tax1: parseFloat(params.tax_total.ll_year),  // 近两年纳税
        Tax2: parseFloat(params.tax_total.l_year),
        Taxtotal: parseFloat(params.tax_total.total), // 总税
      }

      const res = yield call(postBusinessForm, data)
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return res
    },

    // 编辑企业经营数据
    *edit_businessForm( { payload }, { call, put } ) {
      const { params, home, id, key } = payload

      const data = {
        Id: Number(id),
        EntId: Number(key),
        Totalmeans: parseFloat(params.total_property),
        Fixdmeans: parseFloat(params.fixed_property),
        Aptitude: 1,  // 资质
        Debtratio: parseFloat(params.owe_rate), // 负债比率
        Income1: parseFloat(params.pastyear_business.ll_year), // 近两年经营情况
        Income2: parseFloat(params.pastyear_business.l_year),
        Outcome1: parseFloat(params.pastyear_research.ll_year),  // 近两年研发情况
        Outcome2: parseFloat(params.pastyear_research.l_year),
        Tax1: parseFloat(params.tax_total.ll_year),  // 近两年纳税
        Tax2: parseFloat(params.tax_total.l_year),
        Taxtotal: parseFloat(params.tax_total.total), // 总税
      }

      const res = yield call(putBusinessForm, {data, id: Number(id)})
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return res

    },

    // 产品表product
    // id int
    // name
    // image
    // sale
    // percent
    // market
    // mask
    // ent_id
    // product_catalog_id
    // isFirst
    // isHasRight
    *postProductForm( { payload }, { call, put } ) {
      const { params, keys } = payload
      const data = {
        EntId: parseFloat(keys),
        Name: params.product,
        Image: '',
        Market: params.market,
        Sale:params.sales,
        Percent: params.proportion,
        IsFirst: params.isshouantai.toString(),
        IsHasRight: params.iszhuanli.toString(),
        Mask: params.product_type
        // product_catalog_id
      }

      const res = yield call(postProductForm, data)
      const id = keys
      const res1 = yield call(getProductForm, id)
      const newList = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newList.push({
            EntId: item.EntId,
            key: item.Id,
            // introduce: item.EntId,
            isshouantai: Number(item.IsFirst),
            iszhuanli: Number(item.IsHasRight),
            market: item.Market,
            product: item.Name,
            product_type: item.Mask,
            proportion: item.Percent,
            sales: item.Sale,
          })
        })
      }
      return newList
    },

    *putProductForm( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload

      const data = {
        Id: Number(productkey),
        EntId: Number(keys),
        Name: params.product,
        Image: '',
        Market: params.market,
        Sale:params.sales,
        Percent: params.proportion,
        IsFirst: params.isshouantai.toString(),
        IsHasRight: params.iszhuanli.toString(),
        Mask: params.product_type
      }

      const res = yield call(putProductForm, {data, id: Number(productkey)})
      const id = keys
      const res1 = yield call(getProductForm, id)
      const newRewards = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newRewards.push({
            EntId: item.EntId,
            key: item.Id,
            isshouantai: Number(item.IsFirst),
            iszhuanli: Number(item.IsHasRight),
            market: item.Market,
            product: item.Name,
            product_type: item.Mask,
            proportion: item.Percent,
            sales: item.Sale,
          })
        })
      }
      return newRewards

    },




    // 奖励表rewards
    // id int
    // department
    // projectName
    // num
    // time
    *postRewardsForm( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      const data = {
        EntId: parseFloat(keys),
        Department: params.reward_department,
        ProjectName: params.reward_project,
        Num: params.reward_money,
        Time: params.reward_date.toString(),
      }

      const res = yield call(postRewardsForm, data)
      const id = keys
      const res1 = yield call(getRewardsForm, id)
      const newRewards = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newRewards.push({
            EntId: item.EntId,
            key: item.Id,
            reward_department: item.Department,
            reward_project: item.ProjectName,
            reward_money: item.Num,
            reward_date: Number(item.Time),
          })
        })
      }
      return newRewards
      
    },

    *putRewardsForm( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload

      const data = {
        Id: Number(productkey),
        EntId: Number(keys),
        Department: params.reward_department,
        ProjectName: params.reward_project,
        Num: params.reward_money,
        Time: params.reward_date.toString(),
      }

      const res = yield call(putRewardsForm, {data, id: Number(productkey)})
      const id = keys
      const res1 = yield call(getRewardsForm, id)
      const newRewards = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newRewards.push({
            EntId: item.EntId,
            key: item.Id,
            reward_department: item.Department,
            reward_project: item.ProjectName,
            reward_money: item.Num,
            reward_date: Number(item.Time),
          })
        })
      }
      return newRewards

    },


    // 荣誉表honor
    // id int
    // name
    // image
    // time
    // mask
    // department
    *postHonorForm( { payload }, { call, put } ) {
      const { params, keys } = payload
      const data = {
        EntId: parseFloat(keys),
        Name: params.honor_name,
        Image: '',
        Time: params.honor_date.toString(),
        Mask: params.honor_introduce,
        Department: params.honor_unit,
      }

      const res = yield call(postHonorForm, data)
      const id = keys
      const res1 = yield call(getHonorForm, id)
      const newList = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newList.push({
            EntId: item.EntId,
            key: item.Id,
            honor_name: item.Name,
            honor_date: Number(item.Time),
            honor_introduce: item.Mask,
            honor_unit: item.Department,
          })
        })
      }
      return newList
    },

    *putHonorForm( { payload }, { call, put } ) {
      const { params, keys, productkey } = payload

      const data = {
        Id: Number(productkey),
        EntId: parseFloat(keys),
        Name: params.honor_name,
        Image: '',
        Time: params.honor_date.toString(),
        Mask: params.honor_introduce,
        Department: params.honor_unit,
      }

      const res = yield call(putHonorForm, {data, id: Number(productkey)})
      const id = keys
      const res1 = yield call(getHonorForm, id)
      const newList = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newList.push({
            EntId: item.EntId,
            key: item.Id,
            honor_name: item.Name,
            honor_date: Number(item.Time),
            honor_introduce: item.Mask,
            honor_unit: item.Department,
          })
        })
      }
      return newList

    },


    // tec
    *postTecForm( { payload }, { call, put } ) {
      const { params, keys } = payload
      const data = {
        EntId: parseFloat(keys),
        Name: params.core,
        Mask: params.introduce,
        Advantage: params.field,
      }

      const res = yield call(postTecForm, data)
      const id = keys
      const res1 = yield call(getTecForm, id)
      const newList = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newList.push({
            EntId: item.EntId,
            key: item.Id,
            core: item.Name,
            field: item.Advantage,
            introduce: item.Mask,
          })
        })
      }
      return newList
    },

    *putTecForm( { payload }, { call, put } ) {
      const { params, keys, productkey } = payload

      const data = {
        Id: Number(productkey),
        EntId: parseFloat(keys),
        Name: params.core,
        Mask: params.introduce,
        Advantage: params.field,
      }

      const res = yield call(putTecForm, {data, id: Number(productkey)})
      const id = keys
      const res1 = yield call(getTecForm, id)
      const newList = []
      if (res1) {
        // eslint-disable-next-line array-callback-return
        res1.map( item => {
          newList.push({
            EntId: item.EntId,
            key: item.Id,
            core: item.Name,
            field: item.Advantage,
            introduce: item.Mask,
          })
        })
      }
      return newList

    },













    // ent      基础表
    // ent_ops  经营表
    // ent_modify
    // ent_tec
    // ent_rewards
    // ent_honor

    // prouct

























    // 主营产品 添加
    *impoProduct_confirm_add( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.product.unshift(params)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 主营产品 编辑
    *impoProduct_confirm_edit( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.product.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.product[i] = {
                ...home.companyInformation.tableBasicList[index].details_information.product[i],
                ...params
              }
            }
          })

        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 主营产品 删除
    *impoProduct_confirm_delete( { payload }, { call, put } ) {
      const { home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.product.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.product.splice(i, 1)
            }
          })
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 科技创新 添加
    *innovation_confirm_add( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.innovation.unshift(params)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 科技创新 编辑
    *innovation_confirm_edit( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.innovation.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.innovation[i] = {
                ...home.companyInformation.tableBasicList[index].details_information.innovation[i],
                ...params
              }
            }
          })
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 科技创新 删除
    *innovation_confirm_delete( { payload }, { call, put } ) {
      const { home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.innovation.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.innovation.splice(i, 1)
            }
          })
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 主要荣誉 添加
    *honor_confirm_add( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.honor.unshift(params)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 主要荣誉 编辑
    *honor_confirm_edit( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.honor.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.honor[i] = {
                ...home.companyInformation.tableBasicList[index].details_information.honor[i],
                ...params
              }
            }
          })

        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 主要荣誉 删除
    *honor_confirm_delete( { payload }, { call, put } ) {
      const { home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.honor.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.honor.splice(i, 1)
            }
          })
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 奖励情况 添加
    *reward_confirm_add( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.reward.unshift(params)
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 奖励情况 编辑
    *reward_confirm_edit( { payload }, { call, put } ) {
      const { params, home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.reward.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.reward[i] = {
                ...home.companyInformation.tableBasicList[index].details_information.reward[i],
                ...params
              }
            }
          })

        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 奖励情况 删除
    *reward_confirm_delete( { payload }, { call, put } ) {
      const { home, keys, productkey } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          val.details_information.reward.forEach((v, i) => {
            // eslint-disable-next-line eqeqeq
            if (v.key == productkey) {
              home.companyInformation.tableBasicList[index].details_information.reward.splice(i, 1)
            }
          })
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 产品自荐入库理由
    *reason_confirm( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.reason = params.content
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 企业诉求
    *appeal_confirm( { payload }, { call, put } ) {
      const { params, home, keys } = payload
      home.companyInformation.tableBasicList.forEach((val, index) => {
        // eslint-disable-next-line eqeqeq
        if (val.key == keys) {
          home.companyInformation.tableBasicList[index].details_information.appeal = params.content
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 新增管理员
    *addAdministrator( { payload }, { call, put } ) {
      const { values, home } = payload
      home.users_system.unshift(values)
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 管理员用户状态设置
    *resetStatus( { payload }, { call, put } ) {
      const { userName, home } = payload
      home.users_system.forEach((val, index) => {
        if (val.user_name === userName) {
          if (home.users_system[index].status) {
            home.users_system[index].status = 0
          } else {
            home.users_system[index].status = 1
          }
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 重置密码
    *resetPwd( { payload }, { call, put } ) {
      const { userName, pwd, home } = payload
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },
    
    // 导入
    *importConfirm( { payload }, { call, put } ) {
      const { data, home } = payload
      const newList = [...data, ...home.companyInformation.tableBasicList]
      home.companyInformation.tableBasicList = newList
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 创建简讯
    *addRecordIntroduce( { payload }, { call, put } ) {
      const { introduceKey, introduceDetails, home } = payload
      home.recordInformation.recordList.forEach((val, index) => {
        if (val.key === introduceKey) {
          home.recordInformation.recordList[index].introduceDetails = introduceDetails
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },

    // 编辑简讯
    *editRecordIntroduce( { payload }, { call, put } ) {
      const { introduceKey, introduceDetails, home } = payload
      home.recordInformation.recordList.forEach((val, index) => {
        if (val.key === introduceKey) {
          home.recordInformation.recordList[index].introduceDetails = introduceDetails
        }
      })
      yield put({
        type: 'update',
        payload: { ...home },
      })
      return 200
    },




  },









  reducers: {
    save(state, { payload }) {
        return {
          ...state,
          ...payload.HomePage,
          status: false,
        };
    },
    // 更新数据
    update(state, { payload }) {
        return { ...state, ...payload }
    }
  },
};
export default Model;
